package com.aifund.orderservice.service.impl;


import com.aifund.common.dao.UserBindExchangeDao;
import com.aifund.common.entity.AiUserBindExchange;
import com.aifund.orderservice.service.ExchangeService;
import com.aifund.orderservice.service.UserBindExchangeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserBindExchangeServiceImpl implements UserBindExchangeService {

    @Autowired
    UserBindExchangeDao userBindExchangeDao;
    @Autowired
    ExchangeService exchangeService;

    @Override
    public AiUserBindExchange getUserBindExchange(Long userId, Long exchangeId) {
        return userBindExchangeDao.getAllByAiUserIdAndAiExchangeId(userId,exchangeId).get(0);
    }


    @Override
    public List<AiUserBindExchange> getAllByUserIdAndExchangeId(Long userId, Long exchangeId) {
        return userBindExchangeDao.getAllByAiUserIdAndAiExchangeId(userId,exchangeId);
    }

    @Override
    public Long getUserIdByApiKeyAndExchange(String apiKey, String exchange) {
        AiUserBindExchange userBindExchange = userBindExchangeDao.getByApiKeyAndAiExchangeId(apiKey, exchangeService.getIdByExchangeNameEn(exchange));
        return userBindExchange.getAiUserId();
    }

}
